/**/
module console;

import defl.c.ecore.ecore;
import std.stdio;

int count = 0;
Ecore_Timer* timer;

void main()
{
   printf("ecore console\n");
   
   uint passThis = 12;      
   
   catch_uint(cast(void *)&passThis);   
   
	if(ecore_init() > 0)
	{
		ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
			&exit_handler, cast(void *)&passThis);	
		
		timer = ecore_timer_add(1, &timer_handler, null);
		
		if(timer == null)
			printf("Ooops!!! timer is null.\n");
		
		ecore_main_loop_begin();
		ecore_shutdown();
		
		catch_uint(cast(void *)&passThis);
	}
	else
		printf("ecore_init() failed.\n");
}

extern(C)
{
	int catch_uint(void* data)
	{
		uint foo = *(cast(uint *)data); 
		printf("%d\n", foo);
		
		uint* passed = cast(uint *)data;
	
		return 0;
	}	
	
	int exit_handler(void* data, int type, void* event)
	{
		printf("exit_handler() called.\n");
		ecore_main_loop_quit();
		return 0;
	}
	
	int timer_handler(void* data)
	{
		if(count <= 5)
		{
			printf("%d\n", count);
			count++;
			return 1;
		}
		else if(count <= 10)
		{
			printf("%d\n", count);
			ecore_timer_interval_set(timer, 2);
			count++;
			return 1;
		}
		else
		{
			count = 0;
			return 0;
		}		
	}
}
